package com.outsider.util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

public class JD {
  public static JSONObject getProductInfo(String url){
	  JSONObject result=new JSONObject();
	  String code=url.split("/|\\.")[5];
	  result.put("code", code);
	  OkHttp3 okHttp3=OkHttp3.getInstance();
	  JSONArray json=JSONArray.parseArray(okHttp3.get("https://p.3.cn/prices/get?skuid=J_"+code));
	  result.put("price", json.getJSONObject(0).getDouble("p"));
	  return result;
  }
  public static String getProductPic(String url){
	  OkHttp3 okHttp3=OkHttp3.getInstance();
	  String html=okHttp3.get(url);
	  Pattern p=Pattern.compile("//img.*?/n1/.*?.jpg");
	  Matcher matcher=p.matcher(html);
	  matcher.find();
	  return "http:"+matcher.group();
  }
  public static void main(String[] args){
		System.out.println(JD.getProductPic("https://item.jd.com/11957417.html"));
	}

}
